package com.heima.Service.impl;

import com.heima.Serivce.WemediaCilent;
import com.heima.model.Admin.Dtos.ArticleAdminDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.dtos.WmNewsPageReqDto;
import com.heima.model.wemedia.pojos.WmNews;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminArticleService implements com.heima.Service.AdminArticleService {

    @Autowired
    WemediaCilent wemediaCilent;

//    获取待人工审核的文章列表
    @Override
    public ResponseResult GetArticleList(ArticleAdminDto articleAdminDto) {
        WmNewsPageReqDto wmNewsPageReqDto=new WmNewsPageReqDto();
        wmNewsPageReqDto.setPage(articleAdminDto.getPage());
        wmNewsPageReqDto.setSize(articleAdminDto.getSize());
        Integer status = articleAdminDto.getStatus();
        if(status!=null)
        {
            int intValue = status.intValue();
            wmNewsPageReqDto.setStatus((short)intValue);
        }

        return wemediaCilent.GetArticleList(wmNewsPageReqDto);
    }

//    查看文章详情
    @Override
    public ResponseResult GetArticleById(Integer id) {
        return wemediaCilent.GetArticleById(id);
    }

//    审核不通过
    @Override
    public ResponseResult ScanFail(ArticleAdminDto articleAdminDto) {
        return ResponseResult.okResult(articleAdminDto);
    }

//    审核通过
    @Override
    public ResponseResult ScanPass(ArticleAdminDto articleAdminDto) {
        ResponseResult responseResult = wemediaCilent.GetArticleById(articleAdminDto.getId());
        Object data = responseResult.getData();
        WmNews wmNews=(WmNews) data;
        ResponseResult result = wemediaCilent.SaveArticle(wmNews);
        //            登记App端文章id
        if (result.getData() != null)
            wmNews.setArticleId((Long) result.getData());
        wmNews.setStatus((short) 9);
        ResponseResult updateArticleResult = wemediaCilent.UpdateArticle(wmNews);
        return updateArticleResult;
    }
}
